/*********************************************************
* All sources in Hellbound are Copyright (c) 2008 Konijn *
* I Konijn, release all code and data under the terms of *
* of the GNU General Public License (version 2), as well *
* as under the traditional Angband license. Distribution *
* is allowed both under the terms of the GPL (version 2) *
* or under the terms of the traditional Angband license. *
*********************************************************/

//Global Objects

var gear; //This will be attached to the player


//Private Objects


//Initialization

//no initialization
function initGear(){
  gear = new Object();
  gear.pack    = new Array();
	gear.pack.description = "In pack";
	gear.pack.descriptionVerb = "carrying in your pack";
  gear.wield   = new slot( "a" , "Wielding"      , "attacking monsters with"    );
  gear.bow     = new slot( "b" , "Shooting"      , "shooting missiles with"     );
  gear.left    = new slot( "c" , "On left hand"  , "wearing on your left hand"  );
  gear.right   = new slot( "d" , "On right hand" , "wearing on your right hand" );
  gear.neck    = new slot( "e" , "Around neck"   , "wearing around your neck"   );
  gear.lite    = new slot( "f" , "Light source"  , "using to light the way"     );
  gear.body    = new slot( "g" , "On body"       , "wearing on your body"       );
  gear.outer   = new slot( "h" , "About body"    , "wearing on your back"       );
  gear.arm     = new slot( "i" , "On arm"        , "wearing on your arm"        );
  gear.head    = new slot( "j" , "On head"       , "wearing on your head"       );
  gear.hands   = new slot( "k" , "On hands"      , "wearing on your hands"      );
  gear.feet    = new slot( "l" , "On feet"       , "wearing on your feet"       );
  gear.pouch_1 = new slot( "m" , "In pouch"      , "carrying in a pouch"        );
  gear.pouch_2 = new slot( "n" , "In pouch"      , "carrying in a pouch"        );
  gear.pouch_3 = new slot( "o" , "In pouch"      , "carrying in a pouch"        );
  gear.pouch_4 = new slot( "p" , "In pouch"      , "carrying in a pouch"        );
  gear.pouch_5 = new slot( "q" , "In pouch"      , "carrying in a pouch"        );
  gear.pouch_6 = new slot( "r" , "In pouch"      , "carrying in a pouch"        );

  gear.getEquipmentWeight = function(){
    return gear.wield.getWeight()   + 
           gear.bow .getWeight()    +
           gear.left.getWeight()    +
           gear.right.getWeight()   +
           gear.neck.getWeight()    +
           gear.lite.getWeight()    +
           gear.body.getWeight()    +
           gear.outer.getWeight()   +
           gear.arm .getWeight()    +
           gear.head.getWeight()    +
           gear.hands.getWeight()   +
           gear.feet.getWeight()    +
           gear.pouch_1.getWeight() +
           gear.pouch_2.getWeight() +
           gear.pouch_3.getWeight() +
           gear.pouch_4.getWeight() +
           gear.pouch_5.getWeight() +
           gear.pouch_6.getWeight() +
           gear.bow .getWeight()    +
           gear.left.getWeight();
  }

	gear.getPackWeight = function(){
		var key, sum = 0;
		for( key in gear.pack)
			if( gear.pack[key].weight !== undefined )
				sum = sum + gear.pack[key].weight;
		return sum;
	}

	gear.getItem = _getItem;
}


//Public Functions

var slot = function ( alpha , description  , actionVerb){
	this.item = new Object();
	this.description = description;
	this.actionVerb  = actionVerb;
	this.alpha = alpha;
}

  slot.prototype.getWeight = function(){ return this.item.weight===undefined?0    :this.item.weight;      }
  slot.prototype.get       = function(){ return this.item.get   ===undefined?0    :this.item.get();       }
  slot.prototype.has       = function(){ return this.item.has   ===undefined?false:this.item.has();       }

//Private Functions


function _getRepeaterItem( )
{
	var o = repeater.getObject();

	if( o != null )
	{
		if( o.where[o.index] !== undefined && o.where[o.index] !== null )
		{
			//Forget the gizmos.tester.type & hook restriction
			gizmos.tester.type = 0;
			gizmos.tester.hook = NULL;
			//a cookie if you can say this fast 10 times in a row
			return { item : o.where[o.index] , list : o.where };
		}
	}
	repeater.clear();
	return null;
}